/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package RPS;

import SPARQL.Constant;
import SPARQL.SPARQL;
import java.util.HashSet;
import java.util.Objects;
import java.util.Set;
import parser.ParseException;
import parser.SparqlParser;

/**
 *
 * @author mirko
 */
public class EquivalenceMapping {
    
    private Constant const1;
    private Constant const2;
    private Set<MappingAssertion> realatedGmappings ;
    
    public EquivalenceMapping(Constant const1 , Constant const2) throws ParseException {
        this.const1 = const1;
        this.const2 = const2;
        this.realatedGmappings = generateRelatedMapppings(const1, const2);
    }

    @Override
    public int hashCode() {
        int hash = 3;
        hash = 17 * hash + Objects.hashCode(this.const1);
        hash = 17 * hash + Objects.hashCode(this.const2);
        return hash;
    }

    @Override
    public boolean equals(Object obj) {
        if (obj == null) {
            return false;
        }
        if (getClass() != obj.getClass()) {
            return false;
        }
        final EquivalenceMapping other = (EquivalenceMapping) obj;
        if (!Objects.equals(this.const1, other.const1)) {
            return false;
        }
        if (!Objects.equals(this.const2, other.const2)) {
            return false;
        }
        return true;
    }

    public Set<MappingAssertion> getRealatedGmappings() {
        return realatedGmappings;
    }

    public void setRealatedGmappings(Set<MappingAssertion> realatedGmappings) {
        this.realatedGmappings = realatedGmappings;
    }

    /**
     * @return the const1
     */
    public Constant getConst1() {
        return const1;
    }

    /**
     * @param const1 the const1 to set
     */
    public void setConst1(Constant const1) {
        this.const1 = const1;
    }

    /**
     * @return the const2
     */
    public Constant getConst2() {
        return const2;
    }

    /**
     * @param const2 the const2 to set
     */
    public void setConst2(Constant const2) {
        this.const2 = const2;
    }

    @Override
    public String toString() {
        return const1 + " = " + const2;
    }

    private Set<MappingAssertion> generateRelatedMapppings(Constant const1, Constant const2) throws ParseException {
        MappingAssertion map1,map2,map3,map4,map5,map6;
        SPARQL query1,query2,query3,query4,query5,query6;
        query1 = SparqlParser.parse("SELECT ?x ?y WHERE { ?x "+ const1 + " ?y }");
        query2 = SparqlParser.parse("SELECT ?x ?y WHERE { ?x "+ const2 + " ?y }");
        map1 = new MappingAssertion(query1, query2);
        map2 = new MappingAssertion(query2,query1);
        query3 = SparqlParser.parse("SELECT ?x ?y WHERE { "+ const1 + " ?x ?y }");
        query4 = SparqlParser.parse("SELECT ?x ?y WHERE { "+ const2 + " ?x ?y }");
        map3 = new MappingAssertion(query3, query4);
        map4 = new MappingAssertion(query4,query3);
        query5 = SparqlParser.parse("SELECT ?x ?y WHERE { ?x ?y "+ const1 + " }");
        query6 = SparqlParser.parse("SELECT ?x ?y WHERE { ?x ?y "+ const2 + " }");
        map5 = new MappingAssertion(query5, query6);
        map6 = new MappingAssertion(query6,query5);
        Set<MappingAssertion> setmap = new HashSet<MappingAssertion>();
        setmap.add(map1);
        setmap.add(map2);
        setmap.add(map3);
        setmap.add(map4);
        setmap.add(map5);
        setmap.add(map6);
                
               return setmap ;
        
        
       
        
    }
    
}
